
import { _decorator, Component, director, JsonAsset, Label, Prefab, resources, Sprite, sys } from 'cc';
import { Adsdk } from './Adsdk';
import { gameMgr } from './GameMgr';

const { ccclass, property } = _decorator;
 
@ccclass('loading')
export class loading extends Component {

    
    @property(Sprite)
    load: Sprite = null;

    @property(Label)
    loadtxt: Label = null

    load_num = 0;

    httpreq = false

    // roleCongfiDic: Dictionary<number, any> = new Dictionary();
    // equipCongfiDic: Dictionary<number, any> = new Dictionary();
    
    onLoad() {

        this.share()
        this.loadtxt.string = '加载中...' + this.load_num * 100 + '%';
        this.load_num = 0
        if (sys.platform == sys.Platform.WECHAT_GAME) {
            Adsdk.instance.getWxIdFromServer(() => {
                Adsdk.instance.init()
                this.httpreq = true
            }, () => {
                this.httpreq = true
            })
        } else if (sys.platform == sys.Platform.BYTEDANCE_MINI_GAME) {
            Adsdk.instance.init()
            this.httpreq = true
        } else {
            this.httpreq = true 
        }
    }

    share(){
        if(window['tt']||window['wx']){
            //@ts-ignore
            wx.showShareMenu({
                withShareTicket: true,
                menus: ['shareAppMessage', 'shareTimeline'],
            })
            //@ts-ignore
            wx.onShareAppMessage(function () {
            return {
                title: '你有玩过这款超好玩的翡翠合成游戏吗?',
                imageUrl: '',
            }
            })
        }
    }


    update(dt) {
        this.load_num += dt
        this.loadtxt.string = '加载中...'+((this.load_num)*100).toFixed(2)+'%';
        this.load.fillRange = this.load_num;
        if(this.load.fillRange>=0.99&&this.httpreq){
            console.log("加载完成")
            this.loadtxt.string = '加载中...100%';
            director.loadScene('main')
        }
    }

}

